/*
 * Ext GWT - Ext for GWT
 * Copyright(c) 2007-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */
package com.hy.mydesktop.client.mvc.logindialog;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.eclipse.jdt.internal.compiler.ast.ThisReference;

import com.extjs.gxt.ui.client.Registry;
import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.core.FastMap;
import com.extjs.gxt.ui.client.data.BaseModel;
import com.extjs.gxt.ui.client.data.BaseModelData;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.event.Events;
import com.extjs.gxt.ui.client.event.Listener;
import com.extjs.gxt.ui.client.event.WindowEvent;
import com.extjs.gxt.ui.client.mvc.AppEvent;
import com.extjs.gxt.ui.client.mvc.Controller;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.mvc.View;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.Component;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.HtmlContainer;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.button.Button;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.AccordionLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.RootPanel;
import com.hy.mydesktop.client.component.event.AppEvents;

import com.hy.mydesktop.client.mvc.logindialog.LoginPresenter.Display;
import com.hy.mydesktop.client.rpc.ServiceInvoker;
import com.hy.mydesktop.client.rpc.ServiceInvokerAsync;


public class LoginView extends ContentPanel implements Display{

	LoginDialog dialog = null;
   public LoginView() {
	      
		super();
		this.dialog = new LoginDialog();
		dialog.setClosable(false);  
	    dialog.setDraggable(true);
		  
	    dialog.show();
	    this.add(dialog);
	}

	// final ServiceInvokerAsync serviceInvoker = GWT.create(ServiceInvoker.class);


	@Override
	public Button getLoginButton() {
		
		return dialog.getLoginButton();
	}




	@Override
	public TextField<String> getUserNameTextField() {
		return dialog.getUserNameTextField();
	}




	@Override
	public TextField<String> getPasswordTextField() {
		
		return dialog.getPasswordTextField();
	}




	@Override
	public LoginDialog getLoginDialog() {
		
		return dialog;
	}




	@Override
	public Component getComponent() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setComponent(Component component) {
		// TODO Auto-generated method stub
		
	}
  
 

  
  
 
 /* protected void handleEvent(AppEvent event) {
	  dialog.addListener(Events.Hide, new Listener<WindowEvent>() {
	      public void handleEvent(WindowEvent be) {
	        //Dispatcher.forwardEvent(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);  	  
	    	  *//**
	    	   * getServices()
	    	   * 调用后台业务逻辑，返回一些参数对象
	    	   * 如：List<GxtComponentMetaNodeModel> list
	    	   *//*	  
	    	  //if(登录成功)   Dispatcher.forwardEvent(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER,object);
	    	
	    	  if (true) {
	    		  *//**
	    		   * 如果登录成功，调用后台业务逻辑，
	    		   * 返回
	    		   *//*
	    	//	 Dispatcher.get().addController(desktopcontroller);
	    		  *//**
	    		   * 包装windowController 和 dataLoadController
	    		   *//*
	    	//	 Dispatcher.get().addController(windowController);
	    		  
	    		  
	    		  //Dispatcher.get().addController(dataLoadController);
	    		 // Dispatcher.forwardEvent(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);
			}
	    	  
	      }

		
	    });
	  if (event.getType() == AppEvents.DESKTOP_UER_LOGIN_VALIDATE) {
		  final GxtComponentMetaModel gxtComponentMetaModel = this.getDesktopMetaModel();
		    final Controller desktopcontroller = this.createDynamicDesktopController();
		    final Controller windowController = this.createDynamicWindowController2();
		    final Controller dataLoadController = this.createDataLoadController();
		  *//**
			 *  LoginDialog dialog = new LoginDialog();   
			 *  通过Rpc，提交dialog获得的用户名密码
			 *  获得返回值
			 *  如果是ture，
			 *  如果是false，重定向到LoginDialog
			 *//*
		 
		    TextField<String> username = ((TextField<String>)(dialog.getItemByItemId("userName")));
		    TextField<String> password = ((TextField<String>)(dialog.getItemByItemId("password")));
		    System.err.println("$$$$ username " +username.getValue());;
		    System.err.println("$$$$ password " +password.getValue());;
		    
		  final GxtToSeamServiceParameter gxtToSeamServiceParameter = new GxtToSeamServiceParameter();
			gxtToSeamServiceParameter.setServiceComponentName("com.test.server.business.PersonService");
			gxtToSeamServiceParameter.setServiceMethodName("validateLogin0");
			ModelData[] methodArguments2 = new BaseModelData[1];
			methodArguments2[0] = new BaseModel();
			methodArguments2[0].set("username", username.getValue());
			methodArguments2[0].set("password", password.getValue());
			gxtToSeamServiceParameter.setMethodArguments(methodArguments2 );
			
			serviceInvoker.callService(gxtToSeamServiceParameter,
					new AsyncCallback<GxtToSeamServiceResult>() {

						@Override
						public void onSuccess(GxtToSeamServiceResult result) {
							
							List<GxtComponentMetaModel> bmBaseModels = new LinkedList<GxtComponentMetaModel>();						
							ModelData modelData = result.getResult();
							bmBaseModels = modelData.get("listOfModelData");
							//Registry.register(Gxt_desktop.GXTCOMPONENTMETAMODELS,bmBaseModels);
							//map = modelData.get("listOfModelData");
							//System.err.println("&&&&&&&&&&&&&&" + bmBaseModels);
							//Dispatcher.get().addController(desktopcontroller);
							for (GxtComponentMetaModel gxtComponentMetaModel : bmBaseModels) {
								Dispatcher.get().addController(GxtComponentControlerFactory.createGxtComponentController(gxtComponentMetaModel)
								);
							}
							
							  Dispatcher.forwardEvent(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER,new HashMap<String, Object>());
									
							
						 Dispatcher.get().addController(desktopcontroller);
				    		  
				    	 Dispatcher.get().addController(windowController);
				    		  
				    		  
				    		  Dispatcher.forwardEvent(AppEvents.DESKTOP_INIT_FOR_LOGGED_IN_USER);
						
						}

						@Override
						public void onFailure(Throwable caught) {
							System.out.println("#### Rpc Exception is ####"+caught +"When get the List<GxtComponentMetaModel>");
							caught.printStackTrace();
						}
					});
	}
  }
  
 */
	
	
}
